//
//  EmojiPanelView.m
//  Custom_Weibo
//
//  Created by LEO on 12/21/15.
//  Copyright © 2015 Leo_Lei. All rights reserved.
//

#import "EmojiPanelView.h"

@implementation EmojiPanelView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addEmojiView];
        self.backgroundColor = [UIColor lightGrayColor];
    }
    return self;
}

- (void)setEmojiViewDelegate:(id<EmojiViewDelegate>)delegate {
    _emojiView.delegate = delegate;
}

#pragma mark - ADD_EMOJI_INTO_PANEL
- (void)addEmojiView {
    //  1)Create emoji view,and we gonna redesign its frame later.
    _emojiView = [[EmojiView alloc] initWithFrame:CGRectZero];
    _emojiView.backgroundColor = [UIColor clearColor];
    
    //  2)ScrollView created.
    CGRect scrollFrame = CGRectMake(0, 0, kScreenWidth, _emojiView.height);
    _scrollView = [[UIScrollView alloc] initWithFrame:scrollFrame];
    _scrollView.contentSize = CGSizeMake(_emojiView.width, _emojiView.height);
    
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.pagingEnabled = YES;
    
    _scrollView.clipsToBounds = NO;
    _scrollView.delegate = self;
    
    [_scrollView addSubview:_emojiView];
    [self addSubview:_scrollView];
    
    //  3)Page control.
    CGRect pageFrame = CGRectMake(0, _scrollView.bottom, kScreenWidth, 20);
    _pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];
    _pageControl.currentPage = 0;
    _pageControl.numberOfPages = _emojiView.pageNumber;
    _pageControl.autoresizingMask = UIViewAutoresizingNone;
    [self addSubview:_pageControl];
    
    //  The panel view's frame is designed as follows.
    self.height = _scrollView.height + _pageControl.height;
    self.width = kScreenWidth;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    _pageControl.currentPage = scrollView.contentOffset.x / kScreenWidth;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
